package cn.westv.scps.service.areaserver.impl;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import cn.westv.scps.dao.BaseDao;
import cn.westv.scps.domain.AreaSeverEntity;
import cn.westv.scps.service.areaserver.IAreaServerService;
import cn.westv.scps.utils.Page;

/**
 * 地区服务器信息管理实现
 * 
 * @author Administrator
 *
 */
@Service
@Transactional
public class AreaServerServiceImpl implements IAreaServerService {

	@Autowired
	@Qualifier("baseDao")
	private BaseDao dao;

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public List<AreaSeverEntity> find(String hql, Class<AreaSeverEntity> entityClass, Object[] params) {

		return dao.find(hql, entityClass, params);
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public AreaSeverEntity get(Class<AreaSeverEntity> entityClass, Serializable id) {

		return dao.get(entityClass, id);
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public Page<AreaSeverEntity> findPage(String hql, Page<AreaSeverEntity> page, Class<AreaSeverEntity> entityClass,
			Object[] params) {
		return dao.findPage(hql, page, entityClass, params);
	}

	@Override
	@Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
	public String saveOrUpdate(AreaSeverEntity entity) {
		dao.saveOrUpdate(entity);
		return null;
	}

	@Override
	@Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
	public String save(AreaSeverEntity entity) {
		dao.save(entity);
		return entity.getServerId();
	}

	@Override
	@Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
	public String update(AreaSeverEntity entity) {
		dao.update(entity);
		return entity.getServerId();
	}

	@Override
	@Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
	public void saveOrUpdateAll(Collection<AreaSeverEntity> entitys) {
		dao.saveOrUpdateAll(entitys);

	}

	@Override
	@Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
	public String deleteById(Class<AreaSeverEntity> entityClass, Serializable id) {
		dao.deleteById(entityClass, id);
		return null;
	}

	@Override
	@Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
	public void delete(Class<AreaSeverEntity> entityClass, Serializable[] ids) {
		dao.delete(entityClass, ids);
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public List<AreaSeverEntity> querySQL(String SQL, Object[] params, Class<AreaSeverEntity> entityClass) {
		return dao.querySQL(SQL, params, entityClass);
	}

	@Override
	public AreaSeverEntity findByAreaCode(String areaCode) {
		List<AreaSeverEntity> list = dao.find("from AreaSeverEntity where areaCode like ?", AreaSeverEntity.class,
				new Object[] { "%" + areaCode + "%" });
		if (list != null && list.size() > 0) {
			return list.get(0);
		}
		return null;
	}

}
